#include <QtCore>
#include <QCoreApplication>

#include "DprLockManager.h"
#include "DprKeyboard.h"
#include "DprLcd.h"
#include "LcdWidget.h"
#include "gtype.h"

QList<ParmLockEntry> gLockEntries;

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QTextCodec::setCodecForTr(QTextCodec::codecForName("System"));
	QTextCodec::setCodecForCStrings(QTextCodec::codecForName("System"));
//	QTextCodec::setCodecForLocale(QTextCodec::codecForName("System"));

    // Initialize lock manager
    qWarning()<<"Initializing lock manager...";
    DprLockManager *lockManager=new DprLockManager("/dev/DprSwitch");
    if(!lockManager->init())
    {
    	qWarning()<<"Initialize lock manager failed,exit now";
    	return 1;
    }

    qWarning()<<"Initializing keyboard";
    KeyboardManager *keyboard=new KeyboardManager("/dev/DprKeyboard");
    if(!keyboard->start(5000))
    {
    	qWarning()<<"Initializing keyboard failed,exit now";
    	return 1;
    }

    // Initializing lcd
    qWarning()<<"Initializing LCD module";
    DprLcd *lcd=new DprLcd("/dev/DprLcd");
    if(!lcd->init())
    {
    	qWarning()<<"Initializing LCD module failed,exit now";
    	return 1;
    }

    // Initializing widget
    qWarning()<<"Initializing widget manager";
    DprWidgetManager *widgetManager=new DprWidgetManager(lockManager,
    		lcd);
    QObject::connect(keyboard,SIGNAL(sigKeyEvent(int)),widgetManager,
    		SLOT(keyEvent(int)));

    return a.exec();
}
